const { findLog, findAllLog } = require("../model/adminOpaLogs")

const getLoginLog = async (req, res) => {
    let page = req.query['page'] || 1;
    let count = req.query['count'] || 10;
    let counts = {
        skip: (page - 1) * count,
        limit: count - 0
    }
    let query = {}
    if(req.query.name){query.admin=req.query.name }
    let result = await findLog(query, counts)
    if (result) {
        res.send({ status: 1, state: true, msg: "success", data: result })
    } else {
        res.send({ status: 0, state: false, msg: "failed" })
    }
}
//获取单个管理员或者全部管理员的全部操作日志
const getAllLog = async (req, res) => {
    let query = {}
    if (req.body.name){query.admin=req.body.name }
    console.log(query);
    
    let result = await findAllLog(query)
    if (result) {
        res.send({ status: 1, state: true, msg: "全部操作日志获取成功", data: result })
    } else {
        res.send({ status: 0, state: false, msg: "全部操作日志获取失败" })
    }
}

module.exports = {
    getLoginLog, getAllLog
}